<!--
 * @description  :单据管理列表
 * @descriptionDetail:单据管理列表
 * @copyright    : 浙江烟草
 * @author       : dw
 * @create       : 2022-12-19 11:33:33
-->
<template>
  <view>
    <!-- #ifdef H5-ONLY -->
    <theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999">
    </theme-navbar>
    <!-- #endif -->
    <view class="nolicence-search-lay" :style="{'top': isHideNav ? 0 : '44px'}">
      <view class="nolicenSearch">
        <u-search
          shape="round"
          :clearabled="true"
          :showAction="true"
          actionText="确定"
          :animation="true"
          :placeholder="plTitle"
          v-model="searchKey"
          @custom="toSearchList"
        ></u-search>
      </view>
      <view class="tab-lay">
        <u-tabs :is-scroll="false" :list="tabList" :current="currentTab" @change="tabChange"></u-tabs>
      </view>
    </view>

    <view class="content u-page">
      <me-table :i="0" :index="0" :top="120" :load-data="loadData" :height="getListViewHeight()" :init-load="false" ref="mescrollItem0">
        <view slot-scope="d" class="list-item-root">
          <view class="list-lay">
            <waitConfirmManage :itemInfo="d.data"></waitConfirmManage>
          </view>
        </view>
      </me-table>
    </view>
  </view>
</template>

<script>
import MescrollMoreMixin from "@/components/mescroll-uni/mixins/mescroll-more.js";
import meTable from "@/components/me-table.vue";
import waitConfirmManage from "./billManage/waitConfirmManage.vue";
import storeService from '@/service/store/store.service.js';
import {C_STORE_BILL_STATUS,} from "@/service/store/mapping/enum.js"
export default {
  components: {
    meTable,
    waitConfirmManage,
  },
  mixins: [MescrollMoreMixin,],
  data() {
    return {
      tabList: [
        { id: 1, icon: "wuliu2", name: "待确认", text: "待确认", },
        { id: 2, icon: "kuaidi", name: "完成", text: "完成", },
        { id: 3, icon: "quanliqingdan", name: "作废", text: "作废", },
      ],
      currentTab: 0,
      searchKey: "",
      customStyle: {
        padding: "30rpx",
      },
      user: this.$storage.get(this.$rp.common.USER),
      plTitle: "单据编号",
    };
  },
  mounted() {
  },
  methods: {
    getListViewHeight() {
      let p = this.$u.sys().windowHeight - 44 - 57 - 40 - uni.upx2px(10) - this.$u.sys().statusBarHeight + "px";
      // #ifdef H5-DINGDING || H5-WECHAT
      p = this.$u.sys().windowHeight - uni.upx2px(10) - 57 - 40 - this.$u.sys().statusBarHeight + "px";
      // #endif
      return p;
    },
    tabChange(n) {
      this.currentTab = n;
      this.searchKey = "";
      this.$refs.mescrollItem0.listDatas = [];
      this.getMescroll(0).triggerDownScroll();
    },
    toSearchList(e) {
      this.getMescroll(0).triggerDownScroll();
    },
    loadData(page) {
      let params = {
        page: page.num,
        limit: page.size,
        paras: {},
      };
      console.log("@@@@@@", this.currentTab);
      let fun = "";
      return new Promise((resolve, reject) => {
        switch (this.currentTab) {
        case 0:
          {
            params.paras.status = C_STORE_BILL_STATUS.WAIT_CONFIRM; // 待完成
            params.paras.billCodeLike = this.searchKey;
            fun = storeService.billLst;
          }
          break;
        case 1:
          {
            params.paras.status = C_STORE_BILL_STATUS.COMPLETE; // 完成
            params.paras.billCodeLike = this.searchKey;
            fun = storeService.billLst;
          }
          break;
        case 2:
          {
            params.paras.billCodeLike = this.searchKey;
            params.paras.status = C_STORE_BILL_STATUS.TO_VOLID; // 作废
            fun = storeService.billLst; // para
          }
          break;
        }
        fun(params).then((res) => {
          if (res.success) {
            resolve({
              count: res.count,
              data: res.data,
            });
          } else {
            resolve({
              count: 0,
              data: [],
            });
          }
        }).catch((e) => {
          this.$u.toast("请求失败:" + e);
          resolve({
            count: 0,
            data: [],
          });
        });
      });
    },
    updateBackState(param) {
      this.getMescroll(0).triggerDownScroll();
    },
  },
};
</script>

<style scoped lang="scss">
@import "@/style/common/rightMenu.scss";
page{
  background-color: #f3f4f5;

}
.content {
  background-color: #f3f4f5;
  margin-top:35px;
}
.nolicence-search-lay {
  // background-color: #fff;
  position: fixed;
  // #ifndef H5-DINGDING
  top: 44px;
  // #endif
  // #ifdef H5-DINGDING
  top: 0px;
  // #endif
  z-index: 999;
  width: 100%;
  overflow: hidden;
  background-color: #ffffff;
  border-bottom: 1px solid $u-border-color;
}
.nolicenSearch{
  padding: $cm-search-padding-row $cm-search-padding-column;

}
.key-search {
  width: 100%;
  margin: auto;
  padding-left: 2.5%;
  padding-right: 2.5%;
  line-height: 48px;
  border-bottom: 1px solid $u-border-color;
}
.pop-content-lay {
  padding: 20rpx;
  display: flex;
  height: 100%;
  flex-direction: column;
  justify-content: center;
}
.grid-text {
  font-size: 28rpx;
  margin-top: 4rpx;
  color: $u-type-info;
}

.list-lay {
  margin: 10px;
}
.list-item-root {
  margin: 10px;
  border-radius: 15px;
  overflow: hidden;
  border-bottom: 1px solid $u-border-color;
  background-color: #fff;
}
</style>
